﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace SDLHUDEngine
{
    public class NewLibVlc
    {
        [StructLayout(LayoutKind.Sequential)]
        public struct libvlc_instance_t
        {
            public IntPtr p_vlc;
            public IntPtr p_vlm;
            public int b_playlist_locked;
            public uint ref_count;
            public vlc_mutex_t instance_lock;
            public vlc_mutex_t event_callback_lock;
            public IntPtr p_callback_list;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct vlc_mutex_t
        {
            public IntPtr mutex;
            public IntPtr csection;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct libvlc_exception_t
        {
            public Int32 b_raised;
            public Int32 i_code;
            public IntPtr psz_message;

            public void Init()
            {
                libvlc_exception_init(out this);
            }

            public bool WasExceptionRaised()
            {
                if (0 != libvlc_exception_raised(ref this))
                {
                    libvlc_exception_clear(ref this);
                    return true;
                }
                return false;
            }
        }

        [DllImport("libvlc")]
        public static extern IntPtr libvlc_new(int argc, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPStr)]string[] argv, ref libvlc_exception_t ex);

        [DllImport("libvlc")]
        static extern void libvlc_exception_init(out libvlc_exception_t p_exception);
        [DllImport("libvlc")]
        static extern Int32 libvlc_exception_raised(ref libvlc_exception_t p_exception);
        [DllImport("libvlc")]
        static extern void libvlc_exception_clear(ref libvlc_exception_t p_exception);

    }
}
